home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / system / flicb_1.6 / flicb_1 / flicb / packet-drivers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-11  |  14.8 KB  |  442 lines

  1. /* Fairlight's ICB Client                                                    */
  2. /* Copyright 1994, Mark Luljak <fairlite@arcadia.aldridge.sol.net>           */
  3. /*                                                                           */
  4.  
  5.  
  6. #include "flicb.h"
  7.  
  8.  
  9. struct infoback *in_packet_handle(s,pkt,y,wptr,wptr2,nickm,groupm,page,pflg)
  10. int s;
  11. char pkt[STRINGSIZE];
  12. int y;
  13. WINDOW *wptr,*wptr2;
  14. char *nickm;
  15. char *groupm;
  16. int page,pflg;
  17. {
  18.      char gbuf[STRINGSIZE],*gptr;
  19.      char tempbuf[STRINGSIZE],*sptr,*pptr,tbuf2[STRINGSIZE],bogus[STRINGSIZE];
  20.      char *nick, *message;
  21.      char *status, *msg, prvnick[STRINGSIZE],fmsg[STRINGSIZE],*farr[10];
  22.      struct tm *idletime, *logtime;
  23.      static struct infoback infostr;
  24.      struct infoback *iptr;
  25.      static char hinge[12];
  26.      static char hinge2[8];
  27.      int rety,gonno=0;
  28.      int helpflag=0;
  29.      fd_set pending;
  30.      char helpchar;
  31.  
  32.  
  33.      iptr=&infostr;
  34.      iptr->nickinfo=nickm;
  35.      iptr->groupinfo=groupm;
  36.      iptr->dopage=page;
  37.      iptr->pageflag=pflg;
  38.      #ifdef SYSLOG
  39.      openlog("flicb",LOG_PID,LOG_USER);
  40.      syslog(LOG_INFO,"dopage: %d  linesup: %d",iptr->dopage,iptr->linesup);
  41.      #endif
  42.      
  43.      if (iptr->dopage == 1 && iptr->linesup >= WINSIZE) {
  44.                     wmove(wptr2,0,0);
  45.                     wclrtoeol(wptr2);
  46.                     center("                         -< PRESS ANY KEY TO RESUME >-                          ",0,wptr2,1);
  47.                     wrefresh(wptr2);
  48.                     for (helpflag=0;!helpflag;) {
  49.                          FD_ZERO(&pending);
  50.                          FD_SET(fileno(stdin), &pending);
  51.                          if (select(s + 1, &pending, NULL, NULL, NULL) < 0) {
  52.                               perror("mainloop: select");
  53.                               break;
  54.                          }
  55.                          if (FD_ISSET(fileno(stdin), &pending)) {
  56.                               read(fileno(stdin),&helpchar,1*sizeof(char));
  57.                               helpflag=1;
  58.                               iptr->linesup=0;
  59.                          }
  60.                     }
  61.  
  62.      }
  63.      sprintf(tempbuf,"%s",pkt);
  64.      gonno=0;
  65.      #ifdef SYSLOG
  66.      openlog("flicb",LOG_PID,LOG_USER);
  67.      syslog(LOG_INFO,"%s",tempbuf);
  68.      #endif
  69.      sprintf(bogus,"%s",tempbuf);
  70.      sptr=bogus;
  71.      pptr=tempbuf;
  72.      pptr++;
  73.      sprintf(tbuf2,"%s",pptr);
  74.      sprintf(tempbuf,"%s",tbuf2);
  75.      if ((int)*sptr != 'i' && iptr->pageflag==1) {
  76.           iptr->pageflag=0;
  77.           iptr->linesup=0;
  78.      }
  79.      switch ((int)*sptr) {
  80.           case 'b':
  81.                     nick = strtok(tempbuf,SEPCHR);
  82.                     message = strtok(NULL,SEPCHR);
  83.                     rety=w_pub_output(message,nick,y,0,wptr,WINSIZE,0);
  84.                     break;
  85.  
  86.           case 'c': nick = strtok(tempbuf,SEPCHR);
  87.                     sprintf(prvnick,"*%s*",nick);
  88.                     message = strtok(NULL,SEPCHR);
  89.                     rety=w_pub_output(message,prvnick,y,0,wptr,WINSIZE,1);
  90.                     histput(nick);
  91.                     break;
  92.  
  93.       case 'k': nick = strtok(tempbuf,SEPCHR);
  94.                     message = strtok(NULL,SEPCHR);
  95.                     rety=w_beep_output(nick,message,y,0,wptr,WINSIZE);
  96.                     break;
  97.  
  98.           case 'd': status = strtok(tempbuf,SEPCHR);
  99.                     msg = strtok(NULL,SEPCHR);
  100.                     sprintf(gbuf,"%s",msg);
  101.                     rety=w_stat_output(msg,status,y,0,wptr,WINSIZE);
  102.                     for (gptr=strtok(msg," ");gptr;gptr=strtok(NULL," ")) {
  103.                          if (! strcmp("Group",gptr) && !strcmp(status,"Group")) {
  104.                               gptr=strtok(NULL," ");
  105.                               gptr=strtok(NULL," ");
  106.                               gptr=strtok(NULL," ");
  107.                               gptr=strtok(NULL," ");
  108.                               sprintf(hinge2,"%s",gptr);
  109.                               iptr->groupinfo=hinge2;
  110.                               gonno=1;
  111.                               break;
  112.                          }
  113.                          if (! strcmp("group",gptr)) {
  114.                               gptr=strtok(NULL," ");
  115.                   if (gptr && strcmp(gptr,"[NR]") && strtok(status,"RSVP")) {
  116.                                    sprintf(hinge2,"%s",gptr);
  117.                                    iptr->groupinfo=hinge2;
  118.                                    gonno=1;
  119.                                    break;
  120.                               }
  121.                          }
  122.                     }
  123.  
  124.                     if (gonno==1) { break; }
  125.                     
  126.                     for (gptr=strtok(gbuf," ");gptr;gptr=strtok(NULL," ")) {
  127.                          if (! strcmp("nickname",gptr)) {
  128.                               gptr=strtok(NULL," ");
  129.                               if (! strcmp("is",gptr)) {
  130.                                    gptr=strtok(NULL," ");
  131.                                    sprintf(hinge,"%s",gptr);
  132.                                    iptr->nickinfo=hinge;
  133.                                    gonno=1;
  134.                                    break;
  135.                               }
  136.                          }
  137.                     }
  138.                     break;
  139.  
  140.           case 'e': status = strtok(tempbuf,SEPCHR);
  141.                     rety=w_stat_output(status,"Error",y,0,wptr,WINSIZE);
  142.                     break;
  143.  
  144.           case 'g': endwin();
  145.                     printf("Exit Packet Received\n");
  146.                     exit(5);
  147.                     break;
  148.  
  149.           case 'j': status = strtok(tempbuf,SEPCHR);
  150.                     status = strtok(NULL,SEPCHR);
  151.                     msg = strtok(NULL,SEPCHR);
  152.                     rety=w_ver_output(msg,status,y,0,wptr,WINSIZE);
  153.                     break;
  154.  
  155.           case 'i': status=strtok(tempbuf,SEPCHR);
  156.                     #ifdef SYSLOG
  157.                     syslog(LOG_INFO,"info-type= %s",status);
  158.                     #endif
  159.                     if (!strcmp("wl",status)) {
  160.             farr[0]=strtok(NULL,SEPCHR);
  161.             farr[1]=strtok(NULL,SEPCHR);
  162.             farr[2]=strtok(NULL,SEPCHR);
  163.             farr[3]=strtok(NULL,SEPCHR);
  164.             farr[4]=strtok(NULL,SEPCHR);
  165.             farr[5]=strtok(NULL,SEPCHR);
  166.             farr[6]=strtok(NULL,SEPCHR);
  167.             farr[7]=strtok(NULL,SEPCHR);
  168.             farr[8]=strtok(NULL,SEPCHR);
  169.                         sprintf(fmsg,"  %s %-12s  %s  %s  %s@%s %s",farr[0],
  170.                 farr[1],idlestr(farr[2]),
  171.                 ampm(atoi(farr[4]),0),farr[5],farr[6],
  172.                 farr[7],farr[8]);
  173.             #ifdef SYSLOG
  174.                         syslog(LOG_INFO,"PRVNICK: %s",prvnick);
  175.             #endif
  176.                         rety=w_cmd_output(fmsg,status,y,0,wptr,WINSIZE);
  177.                         iptr->linesup+=1;
  178.                         iptr->pageflag=1;
  179.                         break;
  180.                     } 
  181.             if (!strcmp("wh",status) || !strcmp("gh",status)) {
  182.                         rety=0;
  183.                         break; 
  184.                     }
  185.                     if (!strcmp("co",status)) { 
  186.                          msg = strtok(NULL,SEPCHR);
  187.                          rety=w_cmd_output(msg,status,y,0,wptr,WINSIZE);
  188.                          #ifdef SYSLOG
  189.                          syslog(LOG_INFO,"co message: %s",msg);
  190.                          #endif
  191.                          iptr->linesup+=1;
  192.                          iptr->pageflag=1;
  193.                          break;
  194.                     }
  195.                     break;
  196.  
  197.            default: rety=0; 
  198.                     break;
  199.      }
  200.      #ifdef SYSLOG
  201.      closelog();
  202.      #endif
  203.      iptr->yres=rety;
  204.      return(iptr);
  205. }
  206.  
  207. struct infoback *out_packet_handle(s,pkt,y,wptr,pubflag,wptr2,nickm,groupm,page,pflg,liner)
  208. int s;
  209. char pkt[STRINGSIZE];
  210. int y;
  211. WINDOW *wptr;
  212. int pubflag;
  213. WINDOW *wptr2;
  214. char *nickm;
  215. char *groupm;
  216. int page,pflg,liner;
  217. {
  218.      char tempbuf[STRINGSIZE],*sptr,*pptr,tbuf2[STRINGSIZE],bogus[STRINGSIZE];
  219.      char *nick, *message;
  220.      char *status, *msg, prvnick[STRINGSIZE],realmsg[STRINGSIZE];
  221.      char *fairbuf;
  222.      int rety=0,fairfl=0,firstfl=0;
  223.      static struct infoback infostr;
  224.      struct infoback *iptr;
  225.      static char hinge[12];
  226.      static char hinge2[8];
  227.      WINDOW *helpwin;
  228.      int helpflag;
  229.      fd_set pending;
  230.      char helpchar;
  231.      FILE *pp;
  232.      char *combuf,combuffer[MAXMSGSTRLEN];
  233.      int g;
  234.      char *gptr;
  235.  
  236.      #ifdef SYSLOG
  237.      openlog("flicb",LOG_PID,LOG_USER);
  238.      syslog(LOG_INFO,"out_packet %s",pkt);
  239.      #endif
  240.      iptr=&infostr;
  241.      iptr->nickinfo=nickm;
  242.      iptr->groupinfo=groupm;
  243.      iptr->dopage=page;
  244.      iptr->pageflag=pflg;
  245.      iptr->linesup=liner;
  246.      if (iptr->pageflag==1) {
  247.           iptr->pageflag=0;
  248.           iptr->linesup=0;
  249.      }
  250.      sprintf(tempbuf,"%s",pkt);
  251.      sprintf(bogus,"%s",tempbuf);
  252.      if (pubflag) {
  253.           sprintf(realmsg,"b%s",tempbuf);
  254.           packet_write(s,realmsg);
  255.           rety=w_pub_output(tempbuf,nickm,y,0,wptr,WINSIZE,0);
  256.           iptr->yres=rety;
  257.           return(iptr);
  258.      } 
  259.      sptr=bogus;
  260.      pptr=tempbuf;
  261.      pptr++;
  262.      if (*pptr) {
  263.           if (*pptr != ' ') {
  264.                rety=w_stat_output("Unknown Command.  Enter /h for a list of comands.","USER-ERROR",y,0,wptr,WINSIZE);
  265.                iptr->yres=rety;
  266.                return(iptr); 
  267.           }
  268.      }
  269.      sprintf(tbuf2,"%s",pptr);   /* Actual Contents in non-pub msg */
  270.      sprintf(tempbuf,"%s",pptr);
  271.      switch ((int)*sptr) {
  272.           case 'g': sprintf(realmsg,"hg%s%s",SEPCHR,pptr);
  273.                     packet_write(s,realmsg);
  274. /* THIS WAS MOVED TO in_packet_handle()
  275.                     sprintf(hinge2,"%s",pptr);
  276.                     iptr->groupinfo=hinge2;
  277. */
  278.                     break;
  279.  
  280.           case 'e': sprintf(realmsg,"%s",pptr);
  281.                     if (! (pp=popen(realmsg,"r"))) {
  282.                          rety=w_stat_output("No Such Shell Command.","SHELL-ERROR",y,0,wptr,WINSIZE);
  283.                          break; 
  284.                     } 
  285.                     while (!feof(pp)) {
  286.                          combuf=combuffer;
  287.                          fgets(combuf,MAXMSGSTRLEN,pp);
  288.                          if (!feof(pp)) {
  289.                               sprintf(realmsg,"b%s",combuffer);
  290.                               packet_write(s,realmsg);
  291.                               sprintf(prvnick,"*%s*",hinge);
  292.                               rety=w_stat_output(combuffer,"SHELL-OUTPUT",y,0,wptr,WINSIZE);
  293.                          }
  294.                     }
  295.                     pclose(pp);
  296.                     break;
  297.  
  298.           case 'k': sprintf(realmsg,"hboot%s%s",SEPCHR,pptr);
  299.                     packet_write(s,realmsg);
  300.                     break;
  301.  
  302.           case 'p': sprintf(realmsg,"hpass%s%s",SEPCHR,pptr);
  303.                     packet_write(s,realmsg);
  304.                     break;
  305.  
  306.           case 't': sprintf(realmsg,"htopic%s%s",SEPCHR,pptr);
  307.                     packet_write(s,realmsg);
  308.                     break;
  309.  
  310.           case 's': sprintf(realmsg,"hstatus%s%s",SEPCHR,pptr);
  311.                     packet_write(s,realmsg);
  312.                     break;
  313.  
  314.           case 'i': sprintf(realmsg,"hinvite%s%s",SEPCHR,pptr);
  315.                     packet_write(s,realmsg);
  316.                     break;
  317.  
  318.           case 'h': 
  319.                     helpwin=newwin(24,80,0,0);
  320.                     box(helpwin, '|', '-');
  321.                     help(helpwin);
  322.                     for (helpflag=0;!helpflag;) {
  323.                          FD_ZERO(&pending);
  324.                          FD_SET(fileno(stdin), &pending);
  325.                          if (select(s + 1, &pending, NULL, NULL, NULL) < 0) {
  326.                               perror("mainloop: select");
  327.                   break;
  328.                          }
  329.                          if (FD_ISSET(fileno(stdin), &pending)) {
  330.                               read(fileno(stdin),&helpchar,1*sizeof(char));
  331.                               helpflag=1;
  332.                          } 
  333.                     }
  334.                     touchwin(wptr);
  335.                     wrefresh(wptr);
  336.                     touchwin(wptr2);
  337.                     wrefresh(wptr2);
  338.                     break;
  339.  
  340.           case 'n': sprintf(realmsg,"hnick%s%s",SEPCHR,pptr);
  341.                     packet_write(s,realmsg);
  342.                     sprintf(hinge,"*");
  343.                     gptr=pptr;
  344.                     for (g=0;g<12 && *gptr;g++) {
  345.                          sprintf(hinge,"%s%c",hinge,*gptr);
  346.                          gptr++; 
  347.                     }
  348.                     iptr->nickinfo=hinge;
  349.                     break;
  350.  
  351.           case 'b': sprintf(realmsg,"hbeep%s%s",SEPCHR,pptr);
  352.                     packet_write(s,realmsg);
  353.                     break;
  354.  
  355.           case 'w': sprintf(realmsg,"hw%s%s",SEPCHR,pptr);
  356.                     packet_write(s,realmsg);
  357.                     break;
  358.  
  359.           case 'm': nick = strtok(tbuf2," ");
  360.                     histput(nick);
  361.                     #ifdef SYSLOG
  362.                     syslog(LOG_INFO,"nick at /m packet_out %s",nick);
  363.                     #endif
  364.                     sprintf(prvnick,"-TO- %s",nick);
  365.                     if (strlen(nick)<strlen(tempbuf)) {
  366.                          fairbuf=nick;
  367.                          fairbuf+=strlen(nick)+1;
  368.                          sprintf(realmsg,"hm%s%s %s",SEPCHR,nick,fairbuf);
  369.                          packet_write(s,realmsg);
  370.                          rety=w_pub_output(fairbuf,prvnick,y,0,wptr,WINSIZE,0);
  371.                     }
  372.                     #ifdef SYSLOG
  373.                     syslog(LOG_INFO,"nick at /m actual prvnick= %s",prvnick);
  374.                     syslog(LOG_INFO,"nick at /m actual fairbuf= %s",fairbuf); 
  375.                     closelog();
  376.                     #endif
  377.                     break;
  378.  
  379.           case 'c': wclear(wptr);
  380.                     wrefresh(wptr);
  381.                     rety=9999;
  382.                     iptr->linesup=0;
  383.                     break;
  384.  
  385.           case 'q': wclear(wptr2);
  386.                     wclear(wptr);
  387.                     wrefresh(wptr);
  388.                     wrefresh(wptr2);
  389.                     close(s);
  390.                     endwin();
  391.                     exit(0);
  392.                     break;
  393.  
  394.            default: break;
  395.      }
  396.      iptr->yres=rety;
  397.      return(iptr);
  398. }
  399.  
  400. idlestr (num)
  401.         char   *num;
  402. {
  403.         int     seconds = atoi (num);
  404.         static char idletime[8];
  405.  
  406.         if (seconds >= 60) {
  407.                 if (seconds < 3600)
  408.                         sprintf (idletime, "%2dm", seconds / 60);
  409.                 else
  410.                         sprintf (idletime, "%2dh", seconds / 3600);
  411.                 return ((int)idletime);
  412.         } else
  413.                 return ((int) "  -");
  414. }
  415.  
  416. ampm (secs, style)
  417.         time_t  secs;
  418.         int     style;
  419. {
  420.         struct tm *t, *localtime ();
  421.         static char timestr[12];
  422.         int     hr, mn;
  423.  
  424.         t = localtime (&secs);
  425.         hr = t->tm_hour;
  426.         mn = t->tm_min;
  427.  
  428.         if (style) {
  429.                 sprintf (timestr, "%02d:%02d", hr, mn);
  430.                 return ((int)timestr);
  431.         }
  432.         if (hr >= 12)
  433.                 sprintf (timestr, "%2d:%02dpm", (hr > 12) ? hr - 12 : hr, mn);
  434.         else if (hr > 0)
  435.                 sprintf (timestr, "%2d:%02dam", hr, mn);
  436.         else
  437.                 sprintf (timestr, "12:%02dam", mn);
  438.  
  439.         return ((int)timestr);
  440. }
  441.  
  442.